import { Vector3 } from 'three-legacy';
import { ReferencePlaneType } from '../type';

export function calculateTess(
  planeType: string,
  startPoint: Vector3,
  endPoint: Vector3,
  height: number,
) {
  let tess: number[][];
  if (planeType === ReferencePlaneType.XOY) {
    tess = [
      [startPoint.x, startPoint.y, 0],
      [startPoint.x, endPoint.y, 0],
      [endPoint.x, endPoint.y, 0],
      [endPoint.x, startPoint.y, 0],
      [startPoint.x, startPoint.y, 0],

      [startPoint.x, startPoint.y, height],
      [startPoint.x, endPoint.y, height],
      [endPoint.x, endPoint.y, height],
      [endPoint.x, startPoint.y, height],
      [startPoint.x, startPoint.y, height],

      [endPoint.x, startPoint.y, height],
      [endPoint.x, startPoint.y, 0],
      [endPoint.x, endPoint.y, 0],
      [endPoint.x, endPoint.y, height],
      [startPoint.x, endPoint.y, height],
      [startPoint.x, endPoint.y, 0],
    ];
  } else if (planeType === ReferencePlaneType.XOZ) {
    tess = [
      [startPoint.x, 0, startPoint.z],
      [startPoint.x, 0, endPoint.z],
      [endPoint.x, 0, endPoint.z],
      [endPoint.x, 0, startPoint.z],
      [startPoint.x, 0, startPoint.z],

      [startPoint.x, height, startPoint.z],
      [startPoint.x, height, endPoint.z],
      [endPoint.x, height, endPoint.z],
      [endPoint.x, height, startPoint.z],
      [startPoint.x, height, startPoint.z],

      [endPoint.x, height, startPoint.z],
      [endPoint.x, 0, startPoint.z],
      [endPoint.x, 0, endPoint.z],
      [endPoint.x, height, endPoint.z],
      [startPoint.x, height, endPoint.z],
      [startPoint.x, 0, endPoint.z],
    ];
  } else if (planeType === ReferencePlaneType.YOZ) {
    tess = [
      [0, startPoint.y, startPoint.z],
      [0, startPoint.y, endPoint.z],
      [0, endPoint.y, endPoint.z],
      [0, endPoint.y, startPoint.z],
      [0, startPoint.y, startPoint.z],

      [height, startPoint.y, startPoint.z],
      [height, startPoint.y, endPoint.z],
      [height, endPoint.y, endPoint.z],
      [height, endPoint.y, startPoint.z],
      [height, startPoint.y, startPoint.z],

      [height, endPoint.y, startPoint.z],
      [0, endPoint.y, startPoint.z],
      [0, endPoint.y, endPoint.z],
      [height, endPoint.y, endPoint.z],
      [height, startPoint.y, endPoint.z],
      [0, startPoint.y, endPoint.z],
    ];
  }
  return tess;
}
